#! python
# -*- coding: utf-8 -*-

import gym


def first_example(environment='CartPole-v0'):
    env = gym.make(environment)
    env.reset()
    for _ in range(1000):
        env.render()
        env.step(env.action_space.sample()) # take a random action
    env.close()

def second_example(num_episode=20, environment='CartPole-v0'):
    env = gym.make(environment)
    for i_episode in range(num_episode):
        observation = env.reset()
        for t in range(100):
            env.render()
            print(observation)
            action = env.action_space.sample()
            observation, reward, done, info = env.step(action)
            if done:
                print("Episode finished after {} timesteps".format(t+1))
                break
    env.close()


if __name__ == '__main__':
    second_example(1)